from django.shortcuts import render,redirect
from it_jzl.models import *
from django.http import HttpResponse
# Create your views here.
def publish(request):
    id = request.POST.get('aaaaaa')
    print(id)
    a = Site.objects.values()
    b = User.objects.get(pk=3)
    c = Classify.objects.values()
    content = {'sa':a,'ub':b,'ca': c}

    print('------------------')
    print(content)
    return render(request, 'publish.html',content)

def publish_handler(request):
    cover = request.FILES.get('cover')
    title = request.POST.get('title')
    author = request.POST.get('author')
    abstract = request.POST.get('abstract')
    content = request.POST.get('content')
    user=request.POST.get('user')
    site = request.POST.get('site')


    classify = request.POST.get('classify')
    #id = request.POST.get('id')
    #user = User.objects.get(pk=int(id))
    #user = request.POST.get('user')
    #user.u_user = user

    article = Article()
    article.a_cover = cover
    article.a_title = title
    article.a_author = author
    article.a_abstract = abstract
    article.a_content = content
    article.a_isDelete = True
    article.user_id = user
    article.site_id = site

    # a=request.POST.get('site')
    #
    # aa=Article()
    # aa.a_site=a
    # aa.save()


    article.save()
    return redirect('/it_jzl/pay/')


def pay(request):
            # a = request.POST.get('site')
            # print(a)
            # print("########")
    # kkk=Article.objects.all().last().site_id
    # print(kkk)
    # print("******")
    # # for kk in int(k):
    # #     kkk = kk.site_id
    # kkk1 = int(kkk)
    # print('&&&&')
    kkkk =Article.objects.all().last().site_id
    print('###')
    print(kkkk)
    print('###')
    kkkk=str(kkkk)
    a=Site.objects.filter(pk=kkkk).values('si_score')
    print(a)
    content = {'si':a }


    return render(request, 'pay.html',content)

def see(request,id):

    print(id)

    # artical.objects.all().filter(is_Delete=False).last().valuse('id')
    #
    # user=User.objects.get(pk=int(id))
    # b = User.objects.get(pk=3)
    # content = {'ub':b}
    # # print('****')
    # print(content)
    # print('****')
    return render(request, 'see.html')



# def handler(request,id):
#     cover = request.FILES.get('surce')
#     title = request.POST.get('title')
#     author = request.POST.get('author')
#     abstract = request.POST.get('abstract')
#     content = request.POST.get('content')
#     id = request.POST.get('id')
#     user = User.objects.get(pk=int(id))



    # article = Article()
    # article.a_cover = cover
    # article.a_title = title
    # article.a_author = author
    # article.a_abstract = abstract
    # article.a_content = content
    # article.a_isDelete = True
    # article.save()
    # return HttpResponse('/it_jzl/see/')
    #



